package com.way.designpatterncodepratice.singleton;

/**
 * @author liangliwei 80551025
 * @description
 * @date 2020-06-22
 */
public class HungrySingletonStaticBlock {

    /**
     * 饿汉 类加载就初始化 没用到的时候就会消耗内存
     */
    private static HungrySingletonStaticBlock hungrySingleton;

    static {
        System.out.println("HungrySingletonStaticBlock静态代码块");
        hungrySingleton = new HungrySingletonStaticBlock();
    }

    /**
     * 私有化构造器
     */
    private HungrySingletonStaticBlock() {
        System.out.println("HungrySingletonStaticBlock构造器");
    }

    /**
     * 公有的静态获取实例方法
     */
    public static HungrySingletonStaticBlock getInstance(){
        return hungrySingleton;
    }
}
